﻿<phone:PhoneApplicationPage x:Class="DoveSiButta.MapPage"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
	xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    
    xmlns:System="clr-namespace:System;assembly=mscorlib"
    xmlns:my="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps"
    xmlns:models="clr-namespace:DoveSiButta.Models"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"  
    xmlns:local="clr-namespace:DoveSiButta"
	FontFamily="{StaticResource PhoneFontFamilyNormal}"
	FontSize="{StaticResource PhoneFontSizeNormal}"
	Foreground="{StaticResource PhoneForegroundBrush}"
	SupportedOrientations="Portrait" Orientation="Portrait"
	mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
	shell:SystemTray.IsVisible="True">




    <toolkit:TransitionService.NavigationInTransition>
        <toolkit:NavigationInTransition>
            <toolkit:NavigationInTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardIn"/>
            </toolkit:NavigationInTransition.Backward>
            <toolkit:NavigationInTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardIn"/>
            </toolkit:NavigationInTransition.Forward>
        </toolkit:NavigationInTransition>
    </toolkit:TransitionService.NavigationInTransition>
    <toolkit:TransitionService.NavigationOutTransition>
        <toolkit:NavigationOutTransition>
            <toolkit:NavigationOutTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardOut"/>
            </toolkit:NavigationOutTransition.Backward>
            <toolkit:NavigationOutTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardOut"/>
            </toolkit:NavigationOutTransition.Forward>
        </toolkit:NavigationOutTransition>
    </toolkit:TransitionService.NavigationOutTransition>
    
    
    <Canvas x:Name="LayoutRoot">

        <!-- Map View -->
        <Border x:Name="MapView"
                Background="Black"
			    Height="768" Width="480">

            <my:Map Name="Map"
                    CredentialsProvider="{Binding CredentialsProvider}"                    
                    ZoomLevel="{Binding Zoom, Mode=TwoWay}"
                    Center="{Binding Center, Mode=TwoWay}">

                <my:Map.Mode>
                    <my:RoadMode></my:RoadMode>
                    <!--<my:AerialMode ShouldDisplayLabels="True" />-->
                </my:Map.Mode>

                <my:MapItemsControl ItemsSource="{Binding Pushpins}">
                    <my:MapItemsControl.ItemTemplate>
                        <DataTemplate>
                            <my:Pushpin Style="{StaticResource PushpinStyle}"
                                        MouseLeftButtonUp="Pushpin_MouseLeftButtonUp"
                                        Location="{Binding Location}"
                                        Background="{Binding TypeName, Converter={StaticResource PushpinTypeBrushConverter}}"
                                        > <!--Name="{Binding BoxID, Mode=TwoWay}"-->
                                <toolkit:ContextMenuService.ContextMenu>
                                    <toolkit:ContextMenu IsZoomEnabled="False">
                                        <toolkit:MenuItem Style="{StaticResource MenuItemStyle}"/>
                                    </toolkit:ContextMenu>
                                </toolkit:ContextMenuService.ContextMenu>
                                <Image Source="{Binding Icon}" />
                            </my:Pushpin>
                        </DataTemplate>
                    </my:MapItemsControl.ItemTemplate>
                </my:MapItemsControl>

                <Button x:Name="ButtonZoomIn"
                        Style="{StaticResource ButtonZoomInStyle}"
                        HorizontalAlignment="Left" VerticalAlignment="Top"
                        Height="56" Width="56" Margin="8,180,0,0"
                        Click="ButtonZoomIn_Click" />

                <Button x:Name="ButtonZoomOut"
                        Style="{StaticResource ButtonZoomOutStyle}"
                        HorizontalAlignment="Left" VerticalAlignment="Top"
                        Height="56" Width="56" Margin="8,260,0,0"
                        Click="ButtonZoomOut_Click" />

            </my:Map>
        </Border>
        <!-- questa grid e' per debug -->
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <TextBlock Grid.Row="0" x:Name="LatitudeTextBlock"></TextBlock>
            <TextBlock Grid.Row="1" x:Name="LongitudeTextBlock"></TextBlock>
            <TextBlock Grid.Row="2" x:Name="StatusTextBlock" Visibility="Collapsed"></TextBlock>
            <TextBlock Grid.Row="3" x:Name="UseLocationTextBlock" Visibility="Collapsed" ></TextBlock>
            <!--<TextBlock Grid.Row="3" x:Name="BoxesInfoTextBlock"></TextBlock>-->
        </Grid>
        
        <!-- Route View -->
        <Border x:Name="RouteView"
			Height="160" Margin="0"
			Padding="8" RenderTransformOrigin="0.5,0.5" Width="480"
			Background="{StaticResource ControlBackgroundBrush}">
            <Border.RenderTransform>
                <CompositeTransform TranslateY="-160"/>
            </Border.RenderTransform>

            <!-- TODO : Add controls for route calculation -->

        </Border>

        <!-- Directions View -->
        <Border x:Name="DirectionsView"
			VerticalAlignment="Bottom"
			Height="340" RenderTransformOrigin="0.5,0.5" Canvas.Top="428" Width="480"
			Background="{StaticResource DirectionBackgroundBrush}">
            <Border.RenderTransform>
                <CompositeTransform TranslateY="340"/>
            </Border.RenderTransform>

            <!-- TODO : Add control for displaying directions -->

        </Border>
<!--
        <Popup x:Name="PushpinPopup" IsOpen="False" Canvas.Top="330" Canvas.Left="45" Opacity="0">
            <ListBox x:Name="ListBoxPushpinCatalog"
					 Width="392" Height="56"
					 Background="{StaticResource ControlBackgroundBrush}"
					 ItemsSource="{Binding Items}"
                     SelectionChanged="ListBoxPushpinCatalog_SelectionChanged">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal" />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Image Width="56" Height="56" Source="{Binding Icon}" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <ListBox.DataContext>
                    <models:PushpinCatalog />
                </ListBox.DataContext>
            </ListBox>
        </Popup>
-->
        <!-- Visual States -->
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="RouteStates">
                <VisualStateGroup.Transitions>
                    <VisualTransition To="ShowRoute" />
                    <VisualTransition To="HideRoute" />
                </VisualStateGroup.Transitions>
                <VisualState x:Name="ShowRoute">
                    <Storyboard>
                        <DoubleAnimation Duration="0:0:0.3" To="0" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="RouteView" d:IsOptimized="True">
                            <DoubleAnimation.EasingFunction>
                                <CircleEase EasingMode="EaseIn" />
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="HideRoute">
                    <Storyboard>
                        <DoubleAnimation Duration="0:0:0.3" To="-160" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="RouteView" d:IsOptimized="True">
                            <DoubleAnimation.EasingFunction>
                                <CircleEase EasingMode="EaseOut" />
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="DirectionsStates">
                <VisualStateGroup.Transitions>
                    <VisualTransition To="ShowDirections" />
                    <VisualTransition To="HideDirections" />
                </VisualStateGroup.Transitions>
                <VisualState x:Name="ShowDirections">
                    <Storyboard>
                        <DoubleAnimation Duration="0:0:0.3" To="0" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="DirectionsView" d:IsOptimized="True">
                            <DoubleAnimation.EasingFunction>
                                <CircleEase EasingMode="EaseIn" />
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                        <DoubleAnimation Duration="0:0:0.3" To="428" Storyboard.TargetProperty="Height" Storyboard.TargetName="MapView" d:IsOptimized="True">
                            <DoubleAnimation.EasingFunction>
                                <CircleEase EasingMode="EaseIn" />
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="HideDirections">
                    <Storyboard>
                        <DoubleAnimation Duration="0:0:0.3" To="340" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="DirectionsView" d:IsOptimized="True">
                            <DoubleAnimation.EasingFunction>
                                <CircleEase EasingMode="EaseOut" />
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                        <DoubleAnimation Duration="0:0:0.3" To="768" Storyboard.TargetProperty="Height" Storyboard.TargetName="MapView" d:IsOptimized="True">
                            <DoubleAnimation.EasingFunction>
                                <CircleEase EasingMode="EaseOut" />
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="PushpinsStates">
                <VisualStateGroup.Transitions>
                    <VisualTransition To="ShowPushpins" />
                    <VisualTransition To="HidePushpins" />
                </VisualStateGroup.Transitions>
                <!--<VisualState x:Name="ShowPushpins">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Popup.IsOpen)" Storyboard.TargetName="PushpinPopup">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <System:Boolean>True</System:Boolean>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <DoubleAnimation Duration="0:0:0.3" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PushpinPopup" d:IsOptimized="True">
                            <DoubleAnimation.EasingFunction>
                                <CircleEase EasingMode="EaseIn" />
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="HidePushpins">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Popup.IsOpen)" Storyboard.TargetName="PushpinPopup">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <System:Boolean>False</System:Boolean>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <DoubleAnimation Duration="0:0:0.3" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PushpinPopup" d:IsOptimized="True">
                            <DoubleAnimation.EasingFunction>
                                <CircleEase EasingMode="EaseOut" />
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                    </Storyboard>
                </VisualState>-->
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

    </Canvas>

    <!-- Application Bar -->
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar x:Name="applicationBar"
							  IsVisible="True"
							  IsMenuEnabled="False"
							  Opacity="0.7">

            <shell:ApplicationBarIconButton Text="Centra" IconUri="/Resources/Icons/ApplicationBar/Location.png" Click="ButtonLocation_Click" />
            <!-- todo: cliccando l'icona si apre la pagina dei dettagli -->
            <!--<shell:ApplicationBarIconButton Text="Dettagli" IconUri="/Resources/Icons/ApplicationBar/Route.png"  Click="ButtonRoute_Click" />-->
            <!-- todo calcolo del percorso-->
            <!--<shell:ApplicationBarIconButton Text="Directions" IconUri="/Resources/Icons/ApplicationBar/Directions.png"  Click="ButtonDirections_Click" />-->
            <shell:ApplicationBarIconButton Text="Modalità" IconUri="/Resources/Icons/ApplicationBar/Mode.png"  Click="ButtonMode_Click" />

        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

</phone:PhoneApplicationPage>
